package com.amazon.dao.impl;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.amazon.dao.UserDao;
import com.amazon.model.User;

@Repository("userDao")
public class UserDaoImpl implements UserDao{
	@Autowired
	private SessionFactory sessionFactory;
	
	public void getAll() {
		// TODO Auto-generated method stub
	}

	@Override
	public User getById(long id) {
		// TODO Auto-generated method stub
		Session session=sessionFactory.getCurrentSession();
		User user= (User) session.createSQLQuery("select * from user where Id="+id).addEntity(User.class).list().get(0);
		return user==null?null:user;
	}

	@Override
	public void insert(User user) {
		// TODO Auto-generated method stub
		Session session=sessionFactory.getCurrentSession();//openSession();
		session.save(user);
	}
}